var collapsed;
var expanded;
var oTip;

/**
 * isIE5() browser check
 * @return boolean is ie5 or high version return true, else return false.
 */
function isIE5() {
    return document.all && document.getElementById ? true : false;
}

function encodeHTML(s) {
    var str = s;
    if (s) {
        str = s.replace(/&/gi, '&amp;');
        str = str.replace(/>/gi, '&gt;');
        str = str.replace(/</gi, '&lt;');
        str = str.replace(/\"/gi, '&quot;');
    }
    return str;
}

function decodeHTML(s) {
    var str = s;
    if (s) {
        str = s.replace(/&quot;/gi, '"');
        str = str.replace(/&lt;/gi, '<');
        str = str.replace(/&gt;/gi, '>');
        str = str.replace(/&amp;/gi, '&');
    }
    return str;
}

/**
 * @param event object
 * @return srcElem Array[0] is object, Array[1] is event.x,
 *  Array[2] is event.y.
 */
function getEventElement(event) {
    var srcElem = new Array;
    if (isIE5()) {
        srcElem[0] = event.srcElement;
        srcElem[1] = event.x + document.body.scrollLeft;
        srcElem[2] = event.y + document.body.scrollTop;
    } else {
        srcElem[0] = event.target;
        srcElem[1] = event.pageX;
        srcElem[2] = event.pageY
    }
    return srcElem;
}

/**
 * getOffset
 * @param event event object
 * @param obj html object
 * @return array array[0] is left to container, array[1] is top to container.
 */
function getOffsetXY(event,obj) {
    srcElem = getEventElement(event);
    tableMouseDownX = srcElem[1];
    tableMouseDownY = srcElem[2];
    var XY = new Array(tableMouseDownX,tableMouseDownY);
    /* Decrease the offsetRight. For the padding style of .itemtext affects
       the text shift to the left if there is not enough space.*/
    offsetRight = document.body.offsetWidth - obj.offsetWidth - tableMouseDownX - 25;
    offsetBottom = document.body.offsetHeight - obj.offsetHeight - tableMouseDownY;
    offsetLeft = tableMouseDownX - obj.offsetWidth;
    offsetTop = tableMouseDownY -obj.offsetHeight;
    if (offsetRight >= 0 && offsetBottom >= 0) {
    } else {
        if (offsetBottom >= 0 && offsetLeft >= 0) {
            tableMouseDownX = srcElem[1] - obj.offsetWidth;
        } else {
            if (offsetLeft >= 0 && offsetTop >= 0) {
                tableMouseDownX = srcElem[1] - obj.offsetWidth;
                tableMouseDownY = srcElem[2] - obj.offsetHeight;
            } else {
                if (offsetTop>=0 && offsetRight>=0) {
                    tableMouseDownY = srcElem[2] - obj.offsetHeight;
                }
            }
        }
    }
    XY[0] = tableMouseDownX;
    XY[1] = tableMouseDownY;
    return XY;
}

/**
 * get table row
 */
function getRow(srcElem) {
    if (srcElem == null || srcElem.tagName == undefined) {
        return null;
    }
    while (srcElem.tagName != 'TR'
            && srcElem.tagName != 'TBODY'
            && srcElem.tagName != 'TABLE'
            && srcElem != document.documentElement) {
       srcElem = srcElem.parentNode;
    }
    if (!srcElem.getAttribute("onclick")
            && !srcElem.getAttribute("onmouseout")
            && !srcElem.getAttribute("onmouseover")
            && !srcElem.getAttribute("oncontextmenu")
            && !srcElem.onclick
            && !srcElem.onmouseout
            && !srcElem.onmouseover
            && !srcElem.oncontextmenu) {
        srcElem = srcElem.parentNode;
        return getRow(srcElem);
    }
    if (srcElem.tagName == 'TR') {
        return srcElem;
    } else {
        return null;
    }
}

/**
 * get table
 */
function getTable(srcElem) {
    if (srcElem == null || srcElem.tagName == undefined) {
        return null;
    }
    while (srcElem.tagName != 'TABLE' && srcElem != document.documentElement) {
           srcElem = srcElem.parentNode;
    }
    if (srcElem.tagName == 'TABLE') {
        return srcElem;
    } else {
        return null;
    }
}

/**
 * get table header column
 */
function getHeaderColumn(srcElem) {
    if (srcElem == null || srcElem.tagName == undefined) {
        return null;
    }
    while (srcElem.tagName != 'TH' && srcElem != document.documentElement) {
           srcElem = srcElem.parentNode;
    }
    if (srcElem.tagName == 'TH') {
        return srcElem;
    } else {
        return null;
    }
}

/**
 * isReadableCell
 * @param tagName
 * @return boolean
 */
function isReadableCell(tagName) {
    if (tagName == 'INPUT' || tagName == 'TEXTAREA' ||
            tagName == 'SPAN' || tagName == 'A' ||
            tagName == 'SELECT'|| tagName == 'IMG') {
        return true;
    } else {
        return false;
    }
}

/**
 * get table row
 * @param row html table row
 * @return array values
 */
function getCurrentRowValue(row, isChecked, includedTR, isNotEncoded) {
    var rowValue = new Array();
    firstParent = null;
    if (row == null || ((!includedTR) && row.parentNode.tagName != 'TBODY' && row.parentNode.tagName != 'TABLE')) {
        return;
    }
    for (var i = 0; i < row.childNodes.length; i++) {
        var cell = row.childNodes[i];
        /**
         * It's because in Mozilla or NS browser when there exit space
         * or new line between <TD> tags in table row <TR>, it will be regarded
         * as an text node and a child node of the table row.
         */
        if (cell.nodeType == 3) {
        	// text node
           	continue;
        }

        var cellValue = new Array();
        for (var j = 0; j < cell.childNodes.length; j++) {
            var cellChild = cell.childNodes[j];
            if (cellChild.nodeType == 1 && isReadableCell(cellChild.tagName)) {
                if (cellChild.type == 'radio' && cellValue == '') {
                    if (cellChild.checked == true || isChecked != true) {
                        if (isNotEncoded) {
                            cellValue.push(cellChild.value);
                        } else {
                            cellValue.push(encodeHTML(cellChild.value));
                        }
                        break;
                    }
                } else {
                    if (isNotEncoded) {
                        cellValue.push(getRowCellValue(cellChild, isChecked));
                    } else {
                        cellValue.push(encodeHTML(getRowCellValue(cellChild, isChecked)));
                    }
                }
            } else if (cellChild.nodeType == 3) {
                if (isNotEncoded) {
                    cellValue.push(cellChild.nodeValue);
                } else {
                    cellValue.push(encodeHTML(cellChild.nodeValue));
                }
            }
        }
        rowValue.push(cellValue);
    }
    return twoToOneDimensionArray(rowValue);
}

function twoToOneDimensionArray(array) {
    var newValue = new Array();
    for (var i=0; i<array.length; i ++) {
        if (array[i].length > 0) {
            for(var j=0; j<array[i].length; j++){
                newValue.push(array[i][j]);
            }
        } else {
                newValue.push(array[i]);
        }
    }
    return newValue;
}


/**
 * get table cell value
 * @param node html node
 * @return table row cell value
 */
function getRowCellValue(node, isChecked) {
    if (node.tagName == 'INPUT') {
        return getInputValue(node, isChecked);
    }
    if (node.tagName == 'TEXTAREA') {
        return getTextAreaValue(node);
    }
    if (node.tagName == 'SPAN') {
        return getSpanValue(node);
    }
    if (node.tagName == 'A') {
        return getAnchorValue(node);
    }
    if (node.tagName == 'SELECT') {
        return getSelectValue(node);
    }
    if (node.tagName == 'IMG') {
        return getImageValue(node);
    }
}
/**
 * get input node value.
 * input node: radio, checkbox, text, e.g.
 * @param node html node
 * @return input value
 */
function getInputValue(node, isChecked) {
    if (node.type == 'radio' || node.type == 'checkbox') {
        if (node.type == 'radio') {
            var parentNode = node.parentNode;
            if (parentNode != firstParent) {
                firstParent = parentNode;
                var children = parentNode.childNodes;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    if ((child.type == 'radio' && child.checked == true) || (isChecked != true)) {
                        return child.value;
                    }
                }
            }
        } else {
            if (node.checked == true || isChecked != true) {
                return node.value;
            } else {
                return '';
            }
        }
    } else {
        return node.value;
    }
}
/**
 * get select node value.
 * select node: simple select, multiple select,e.g.
 * @param html node
 * @return select value
 */
function getSelectValue(node) {
    if (isNull(node)) {
        return;
    }
    if (node.multiple == false) {
        var tmp = new Array;
        if (node.selectedIndex > -1) {
            tmp[0] = node.options[node.selectedIndex].value;
            tmp[1] = node.options[node.selectedIndex].text;
        }
        return tmp;
    } else {
        var tmpArray = new Array();
        if (node.options) {
            for (var i = 0; i < node.options.length; i++) {
                if (node.options[i].selected) {
                    var tmp = new Array();
                    tmp[0] = node.options[i].value;
                    tmp[1] = node.options[i].text;
                    tmpArray.push(tmp);
                }
            }
        }
        return tmpArray;
    }
}
function getSelectionValue(selectionId) {
    var tmpNode = document.getElementById(selectionId);
    if (isNull(tmpNode)) {
        return;
    }

    var arr = getSelectValue(tmpNode);
    if (tmpNode.multiple) {
        var tmpArr = new Array();
        for (var i = 0; i < arr.length; i++) {
            tmpArr.push(arr[i][0]);
        }
        return tmpArr;
    } else {
        var tmpValue = tmpNode.value;
        if (tmpValue) {
            return tmpValue;
        } else {
            return '';
        }
    }
}
function setSelectionSelectedValue(selectionId, selectedValue, isMutiple) {
    var tmpSelection = document.getElementById(selectionId);
    for (var i = 0; i < tmpSelection.options.length; i++) {
        if (tmpSelection.options.item(i).value == selectedValue) {
            tmpSelection.options.item(i).selected = true;
            break;
        }
    }
    if (isMutiple) {
        for (var i = 0; i < selectedValue.length; i++) {
            setSelectionSelectedValue(selectionId, selectedValue[i]);
        }
    }
    return;
}

/**
 * get textarea node value.
 * @return textarea value
 */
function getTextAreaValue(node) {
    return node.value;
}
/**
 * get anchor node value.
 * @param node html node
 * @return anchor value
 */
function getAnchorValue(node) {
    return node.href;
}
/**
 * get span node value.
 * @param node html node
 * @return span value
 */
function getSpanValue(node) {
    if ((node.childNodes != null) && (node.childNodes.length > 0)) {
        return node.childNodes[0].nodeValue;
    } else {
        return '';
    }
}
/**
 * get image node value.
 * @param node html node
 * @return span value
 */
function getImageValue(node) {
    return node.src;
}
/**
 * Add an additional row which contains the inputted currentNode
 * to the inputted xml node, and reset the input forms' id with the
 * parameter resetList in an Array.
 * @param xmlNode html node
 * @param removedNode html node
 * @param resetList string array
 */
function addNodeRow(xmlNode, currentNode, resetList, resetValues) {
    if (xmlNode == null || xmlNode == undefined ||
        currentNode == null || currentNode == undefined) {
        return;
    }
    var cloneRow = currentNode.cloneNode(true);
    var currentNodeParent = currentNode.parentNode;
    if (resetList != '') {
        resetNode(cloneRow, resetList, resetValues);
    }
    if (currentNode.nextSibling == null) {
        currentNodeParent.appendChild(cloneRow);
    } else {
        var nextSibling = currentNode.nextSibling;
        currentNodeParent.insertBefore(cloneRow, currentNode.nextSibling);
    }
}
/**
 * copy a table row
 * @param xmlNode html node
 * @param currentNode html node
 */
function copyNodeRow(xmlNode, currentNode) {
    if (xmlNode == null || xmlNode == undefined ||
        currentNode == null || currentNode == undefined) {
        return;
    }
    addNodeRow(xmlNode, currentNode, '');
}
/**
 * Remove a specific row which contains the given removeNode
 * from the xml node.
 * @param xmlNode html node
 * @param removedNode html node
 */
function removeNodeRow(xmlNode, currentNode) {
    if (xmlNode == null || xmlNode == undefined ||
        currentNode == null || currentNode == undefined) {
        return;
    }
    var currentNodeParent = currentNode.parentNode;
    currentNodeParent.removeChild(currentNode);
}
/**
 * set the node value use resetList
 * @param theNode html node
 * @param resetList string array
 */
function resetNode(theNode, resetList, resetValues) {
    var tdNodes = theNode.getElementsByTagName('TD');
    var index = 0;
    var nodes = new Array;
    for (var i = 0; i < tdNodes.length; i++) {
        if (tdNodes[i].childNodes.length < 0) {
            return;
        }
        for (var j = 0; j < tdNodes[i].childNodes.length; j++) {
            if (tdNodes[i].childNodes[j].nodeName == 'INPUT'
                || tdNodes[i].childNodes[j].nodeName == 'TEXTAREA'
                || tdNodes[i].childNodes[j].nodeName =='SELECT'
                || tdNodes[i].childNodes[j].nodeName =='A'
                || tdNodes[i].childNodes[j].nodeName =='SPAN'
                || tdNodes[i].childNodes[j].nodeName == 'IMG') {
                nodes[index] = tdNodes[i].childNodes[j];
                index++;
            }
        }
    }
    for (var i = 0; i < index; i++) {
        if (i < resetList.length) {
            nodes[i].setAttribute('name', resetList[i]);
            nodes[i].setAttribute('id', resetList[i]);
            var tagName = '';
            if (nodes[i].tagName == 'INPUT') {
                setInputValue(nodes[i], '');
                tagName = 'INPUT';
            }
            if (nodes[i].tagName == 'SELECT') {
                setSelectValue(nodes[i], '');
                tagName = 'SELECT';
            }
            if (nodes[i].tagName == 'TEXTAREA') {
                setTextAreaValue(nodes[i],'');
                tagName = 'TEXTAREA';
            }
            if (nodes[i].tagName == 'A') {
                setAnchorValue(nodes[i], '');
                tagName = 'A';
            }
            if (nodes[i].tagName == 'SPAN') {
                setSpanValue(nodes[i], resetList[i]);
                tagName = 'SPAN';
            }
            if (nodes[i].tagName == 'IMG') {
                setImageValue(nodes[i], '');
                tagName = 'IMG';
            }
            if (resetValues != null && resetValues != '') {
                setNodeValueByTagName(theNode, resetList[i], tagName, resetValues[i], false);
            }
        }
    }
}


/**
 * find the table row node by give attributeId and tagName, set the parameter value to it
 * different html node has different ways store the value, detail see above comment of function
 * getAllNodesValueByTagName()
 * @param node html node
 * @param attributeId html tag id
 * @param tagName html tag name
 * @param value string
 */
function setNodeValueByTagName(node, attributeId, tagName, value, isChecked) {
    var children = node.getElementsByTagName(tagName);
    if (children == null) return null;
    for (var i = 0; i < children.length; i++) {
        var idNode = children[i];
        if (idNode.id == attributeId) {
            if (idNode.tagName == 'INPUT') {
                setInputValue(idNode, value, isChecked);
            }
            if (idNode.tagName == 'SELECT') {
                setSelectValue(idNode, value)
            }
            if (idNode.tagName == 'TEXTAREA') {
                setTextAreaValue(idNode, value)
            }
            if (idNode.tagName == 'A') {
                setAnchorValue(idNode, value)
            }
            if (idNode.tagName == 'SPAN') {
                setSpanValue(idNode, value);
            }
            if (idNode.tagName == 'IMG') {
                setImageValue(idNode, value);
            }
        }
    }
}
/**
 * set input node value.
 * @param node html node
 * @param value string
 */
function setInputValue(node, value, isChecked) {
    if ((isChecked) && (node.type == 'radio' || node.type == 'checkbox')) {
        if (node.type == 'radio') {
            for (var i = 0; i < node.parentNode.childNodes.length; i++) {
                if (node.type == 'radio' && node.value == value) {
                    node.checked = true;
                    return;
                }
            }
        } else {
            if (node.value == value) {
                node.checked = true;
            }
        }
    } else {
        node.value = value;
    }
}
/**
 * set select node value.
 * @param node html node
 * @param value string
 */
function setSelectValue(node, value) {
    if (node.multiple == false) {
        if (node.options) {
            for (var i = 0; i < node.options.length; i++) {
                if (node.options[i].value == value) {
                    node.selectedIndex = node.options[i].index;
                    return;
                }
            }
        }
    } else {
        if (node.options) {
            for (var i = 0; i < node.options.length; i++) {
                if (node.options[i].value == value) {
                    node.options[i].selected = true;
                }
            }
        }
    }
}
/**
 * set textarea node value.
 * @param node html node
 * @param value string
 */
function setTextAreaValue(node, value) {
    node.value = value;
}
/**
 * set anchor node value.
 * @param node html node
 * @param value string
 */
function setAnchorValue(node, value) {
    node.href = value;
}
/**
 * set span node value.
 * @param node html node
 * @param value string
 */
function setSpanValue(node, value) {
    if (node.childNodes[0] == null) {
        var textNode = document.createTextNode('');
        node.appendChild(textNode);
    }
    node.childNodes[0].nodeValue = value;
}
/**
 * set imgae node value.
 * @param node html node
 * @param value string
 */
function setImageValue(node, value) {
    node.src = value;
}
/**
 * get all table checkbox value by attributeId
 * @param node html node
 * @param value string
 */
function getCheckedValue(node, attributeId) {
    var checkedValue = new Array();
    checkedValue = getAllNodeValueByTagName(node, attributeId, "INPUT");
    return checkedValue;
}
/**
 * The table columns have difference id
 * This function can get all table nodes value by given attributeId and tagName
 * case :
 *     input object: radio group will return the selected option's value
 *                   checkbox will return the checked value
 *                   other input object return the default value
 *     select object: simple select will return the selected value and the selected text
 *                    multiple select will return all the selected value and the selected text
 *     textarea object: return the inner text
 *     span object:     return the inner text
 *     anchor object:   return it's href
 * If the node hasn't value then will return a '' or undefined value;
 * All return values store in tagValueArray array.
 * @param node html node
 * @param attributeId html tag id
 * @param tagName html tag name
 * @return array of values
 */
function getNodeValueById(node, attributeId, tagName, isChecked) {
    var tagAllArray = new Array;
    var tagValueArray = new Array;
    firstParent = null;   //use in radio group
    tagAllArray = node.getElementsByTagName(tagName);
    for (var i = 0; i < tagAllArray.length; i++) {
        var idNode = tagAllArray[i];
        if (idNode.id == attributeId) {
            if (idNode.tagName == 'INPUT') {
                var value = getInputValue(idNode, isChecked);
                if (value != undefined) {
                    tagValueArray.push(value);
                }
            }
            if (idNode.tagName == 'SELECT') {
                tagValueArray.push(getSelectValue(idNode));
            }
            if (idNode.tagName == 'TEXTAREA') {
                tagValueArray.push(getTextAreaValue(idNode));
            }
            if (idNode.tagName == 'A') {
                tagValueArray.push(getAnchorValue(idNode));
            }
            if (idNode.tagName == 'SPAN') {
                tagValueArray.push(getSpanValue(idNode));
            }
            if (idNode.tagName == 'IMG') {
                tagValueArray.push(getImageValue(idNode));
            }
        }
    }
    return tagValueArray;
}
/**
 * The table columns have difference id
 * This function can get all table nodes value by given attributeId and tagName
 * case :
 *     input object: radio group will return the selected option's value
 *                   checkbox will return the checked value
 *                   other input object return the default value
 *     select object: simple select will return the selected value and the selected text
 *                    multiple select will return all the selected value and the selected text
 *     textarea object: return the inner text
 *     span object:     return the inner text
 *     anchor object:   return it's href
 * If the node hasn't value then will return a '' or undefined value;
 * All return values store in tagValueArray array.
 * @param node html node
 * @param attributeId html tag id
 * @param tagName html tag name
 * @return array of values
 */
function getNodeValueByIdGroup(node, attributeId, tagName, isChecked) {
    var tagAllArray = new Array;
    var tagValueArray = new Array;
    firstParent = null;   //use in radio group
    tagAllArray = node.getElementsByTagName(tagName);

    //if (tagAllArray.length) {
        for (var i = 0; i < tagAllArray.length; i++) {
            var idNode = tagAllArray[i];
            if (idNode.id.indexOf(attributeId) == 0) {
                if (idNode.tagName == 'INPUT') {
                    var value = getInputValue(idNode, isChecked);
                    if (value) {
                        tagValueArray.push(value);
                    }
                }
                if (idNode.tagName == 'SELECT') {
                    tagValueArray.push(getSelectValue(idNode));
                }
                if (idNode.tagName == 'TEXTAREA') {
                    tagValueArray.push(getTextAreaValue(idNode));
                }
                if (idNode.tagName == 'A') {
                    tagValueArray.push(getAnchorValue(idNode));
                }
                if (idNode.tagName == 'SPAN') {
                    tagValueArray.push(getSpanValue(idNode));
                }
                if (idNode.tagName == 'IMG') {
                    tagValueArray.push(getImageValue(idNode));
                }
            }
        }
    /*}
    else {
        if (node.id.indexOf(attributeId) == 0) {
            if (node.tagName == 'INPUT') {
                var value = getInputValue(node, isChecked);
                if (value) {
                    tagValueArray.push(value);
                }
            }
            if (node.tagName == 'SELECT') {
                tagValueArray.push(getSelectValue(node));
            }
            if (node.tagName == 'TEXTAREA') {
                tagValueArray.push(getTextAreaValue(node));
            }
            if (node.tagName == 'A') {
                tagValueArray.push(getAnchorValue(node));
            }
            if (node.tagName == 'SPAN') {
                tagValueArray.push(getSpanValue(node));
            }
            if (node.tagName == 'IMG') {
                tagValueArray.push(getImageValue(node));
            }
        }
    }*/
    return tagValueArray;
}
/**
 * check or uncheck all checkbox which name is parameter "name" of the node
 * @param event event object
 * @param node html node
 * @param name checkbox name
 */
function checkAll(event, node, name) {
    oInput = node.getElementsByTagName('INPUT');
    for (var i = 0; i < oInput.length; i++) {
        if (oInput[i].type == 'checkbox' && oInput[i].name == name) {
            oInput[i].checked = getEventElement(event)[0].checked;
        }
    }
}

/**
 * check or uncheck all checkbox which name is parameter "name" of the node
 * @param event event object
 * @param name checkbox name
 */
function checkAllByIdGroup(event, id) {
    var node = getTable(getEventElement(event)[0]);
    oInput = node.getElementsByTagName('INPUT');
    for (var i = 0; i < oInput.length; i++) {
        if (oInput[i].type == 'checkbox' && oInput[i].id.indexOf(id) == 0) {
            oInput[i].checked = getEventElement(event)[0].checked;
        }
    }
}

/**
 * check whether element is form element: <input>, <select>, <textarea> or <A>
 * @param element DOM object
 * @return true or false
 */
function isFormElementNode(element) {
    if (element.tagName == 'INPUT'
            || element.tagName == 'SELECT'
            || element.tagName == 'TEXTAREA'
            || isHyperLink(element)) {
        return true;
    } else {
        return false;
    }
}

function isHyperLink(element) {
    if (element.tagName == 'A') {
        return true;
    } else if (element.tagName == 'IMG') {
        var id = element.id;
        // for avoid the context menu button (last column at view)
        if (((id == 'undefined') || (id.indexOf('$ContextMenu') != 0))
            && (element.parentNode.tagName == 'A')) {
            return true;
        }

    } else {
        return false;
    }
}

/**
 * write content into the given node.
 * in ie5 or high version use innerHTML
 * in nescape or hight version use creteContextualFragment
 */
function writeContent(node, content) {
    if (isIE5())
        node.innerHTML = content;
    else {
        rng = document.createRange();
        rng.setStartBefore(node);
        htmlFrag = rng.createContextualFragment(content);
        while (node.hasChildNodes())
            node.removeChild(node.lastChild);
        node.appendChild(htmlFrag);
    }
}
/**
 * judge the current node whether belong to table header.
 * @param currentNode: event element.
 * @return if is belong to table header return true, or return false.
 */
function isTableHeaderElement(currentNode) {
    if (currentNode == null && currentNode.tagName == undefined) {
        return false;
    }
    if (currentNode.tagName == 'TABLE' || currentNode.tagName == 'TBODY') {
        return false;
    }
    while (currentNode.tagName != 'THEAD' && currentNode.tagName != 'TABLE' &&
           currentNode.tagName != 'TBODY') {
        currentNode = currentNode.parentNode;
    }

    return (currentNode.tagName == 'THEAD') ? true : false;
}
/**
 * judge the current node whether belong to table body.
 * @param currentNode: event element.
 * @return if is belong to table header return true, or return false.
 */
function isTableBodyElement(currentNode) {
    if (currentNode == null || currentNode.tagName == undefined) {
        return false;
    }
    if (currentNode.tagName == 'TABLE' || currentNode.tagName == 'THEAD') {
        return false;
    }
    while (currentNode.tagName != 'TBODY' && currentNode.tagName != 'TABLE' &&
           currentNode.tagName != 'THEAD') {
        currentNode = currentNode.parentNode;
    }
    return (currentNode.tagName == 'TBODY') ? true : false;
}

/**
 * judge the current node whether belong to table <tr>.
 * @param element is a dom object
 * @return tr object or false
 */
function isTableRow(currentNode) {
    while (currentNode.tagName != 'TR' && currentNode.tagName != 'TABLE') {
        currentNode = currentNode.parentNode;
    }
    return ((currentNode.tagName == 'TR') ? currentNode : false);
}
/* mouseOverCurrentRow which is selected */
mouseOverCurrentRow = null;

/**
 * mouse over event on menu
 */
function mouseOverHighlight(event, className, noHighlight) {
    var srcElem = getEventElement(event)[0];
    var row = getRow(srcElem);
    if (row == null) {
        return;
    }
    if (row.rowIndex == noHighlight) {
        return;
    }
    row.className = className;
    mouseOverCurrentRow = row;
}
/**
 * mouse out event on menu
 */
function mouseOutHighlight(className, noHighlight) {
    if (mouseOverCurrentRow == null) {
        return;
    }
    if (mouseOverCurrentRow.rowIndex == noHighlight) {
        return;
    }
    mouseOverCurrentRow.className = className;
}
/**
 * return the checked row
 * @param node html node
 * @param attributeId html tag id
 * @return array of tr object
 */
function getCheckedRow(node, attributeId) {
    var tagAllArray = new Array;
    var rowArray = new Array;
    tagAllArray = node.getElementsByTagName('INPUT');
    for (var i = 0; i < tagAllArray.length; i++) {
        var idNode = tagAllArray[i];
        if (idNode.id.indexOf(attributeId) == 0) {
            if (idNode.tagName == 'INPUT') {
                if(getInputValue(idNode, true)) {
                    var row = isTableRow(idNode);
                    if (row) {
                        rowArray.push(row);
                    }
                }
            }
        }
    }
    return rowArray;
}

/**
 * return the checked row value
 * @param xmlNode html node
 * @return value of the node
 */
function getRowValue(xmlNode) {
    var node = xmlNode;
    while (node.tagName != "TR") {
        if (node.tagName == "TABLE") {
            return null;
        }
        node = node.parentNode;
    }
    return node;
}

/**
 * do nothing event (for checkbox)
 */
function doNothing(e) {
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    return;
}

/**
 * @return boolean is when the data have value
 * (use to check whether the checkbox is checked)
 */
function haveData(data) {
    if (data.length == 0) return false;
    var strData = new String(data);
    var arrData = strData.split(",");
    for (var i = 0; i < arrData.length; i ++) {
        if (arrData[i] != "") {
            return true;
        }
    }
    return false;
}
/**
 * @return the next column values of checkBox checked
 */
function getValues(node, attributeId, tagName, isChecked, column) {
    var tagAllArray = new Array;
    var tagValueArray = new Array;
    var columnValue = column;
    if (columnValue == null) {
        columnValue = 1;
    }
    var isNoNeedCheck = true;
    if (isChecked) {
        isNoNeedCheck = false;
    }
    tagAllArray = node.getElementsByTagName(tagName);
    for (var i = 0; i < tagAllArray.length; i++) {
        var idNode = tagAllArray[i];
        if (idNode.id.indexOf(attributeId) == 0) {
            if (idNode.tagName == 'INPUT' && (isNoNeedCheck || idNode.checked == true)) {
                var currentRow = isTableRow(idNode);
                var td = getCurrentRowValue(currentRow);
                var value = td[columnValue];
                if (value != undefined) {
                    tagValueArray.push(value);
                }
            }
        }
    }
    return tagValueArray;
}

/**
 * @return boolean is true when the value is contained in the data array
 */
function containsEntry(data, value) {
    if (value == '') return true;
    var result = false;
    for (var i = 0; i <data.length; i++) {
        if ((data[i] != '') && (data[i] == value)) {
            result = true;
            break;
        }
    }
    return result;
}


/**
 * @return removed the empty items
 */
function removeEmptyItems(data) {
    var result = new Array();
    for (var i = 0; i <data.length; i++) {
        if (data[i] != '') {
            result.push(data[i]);
        }
    }
    return result;
}
/**
 * table sorting function
 */
function sortAction(e, oForm, attribute, sortingFieldId, order, prefix) {
    var len = arguments.length;
    var thisPrefix = '';
    if (len==6){
        thisPrefix = prefix;
    }
    var srcElem = getHeaderColumn(getEventElement(e)[0]);
    srcElem = srcElem.firstChild;
    if (srcElem != null && srcElem.id != '') {
        oForm.elements[thisPrefix + attribute['sortingFieldId']].value =
            srcElem.id;

        var sortType = eval(thisPrefix + "sortingType[sortingFieldId]");
        if (sortingFieldId == srcElem.id) {
            if (sortType == 'asc') {
                order = order == 0 ? 2 : 0;
            } else if (sortType == 'desc') {
                order = order == 1 ? 2 : 1;
            } else if (sortType == 'both') {
                order = (order + 1) % 3;
            }
        } else {
            sortType = eval(thisPrefix + "sortingType[srcElem.id]");

            if (sortType == 'asc') {
                order = 0;
            } else if (sortType == 'desc') {
                order = 1;
            } else if (sortType == 'both') {
                order = 0;
            }
        }
        oForm.elements[thisPrefix + attribute['order']].value = order;

        oForm.elements[thisPrefix + attribute['viewAction']].value =
            attribute['actionOrderBy'];
        submitForm(oForm);
    }
}
/**
 * page refresh function
 */
function refreshPageAction(oForm, attribute, prefix) {
    var len = arguments.length;
    var thisPrefix = '';
    if (len==3){
        thisPrefix = prefix;
    }
    oForm.elements[thisPrefix + attribute['viewAction']].value =
        attribute['actionRefresh'];
    submitForm(oForm);
}
/**
 * function goToPage
 */
function goToPageAction(e, oForm, attribute, prefix) {
    var len = arguments.length;
    var thisPrefix = '';
    if (len==4){
        thisPrefix = prefix;
    }
    var selection = getRowCellValue(getEventElement(e)[0]);
    oForm.elements[thisPrefix + attribute['startRow']].value =
        parseInt(selection[0]);
    oForm.elements[thisPrefix + attribute['endRow']].value =
        parseInt(selection[0]) + pageSize - 1;
    oForm.elements[thisPrefix + attribute['viewAction']].value =
        attribute['actionJumpToPage'];
    submitForm(oForm);
}
/**
 * page cleanup function
 */
function cleanupViewAttributes(oForm, attribute, prefix) {
    var len = arguments.length;
    var thisPrefix = '';
    if (len==3){
        thisPrefix = prefix;
    }
    oForm.elements[thisPrefix + attribute['startRow']].value = 1;
    oForm.elements[thisPrefix + attribute['endRow']].value = pageSize;
    oForm.elements[thisPrefix + attribute['sortingFieldId']].value = '';
    oForm.elements[thisPrefix + attribute['order']].value = '';
    oForm.elements[thisPrefix + attribute['viewAction']].value = '';
    oForm.elements[thisPrefix + 'criteriaData'].value = '';
    oForm.elements[thisPrefix + 'isCriteriaEncoded'].value = 'false';
    oForm.elements[thisPrefix + 'advancedSearchCriteria'].value = '';
    oForm.elements[thisPrefix + 'advancedSearchCriteria'].value = '';
}


/**
 * Checks whether the row is the first row
 */
function isTheFirstRow(row) {
    if (row.previousSibling == null) {
        return true;
    } else {
        return false;
    }
}

/**
 * Checks whether the row is the second row
 */
function isTheSecondRow(row) {
    if (row.previousSibling == null) {
        return false;
    } else {
        if (isTheFirstRow(row.previousSibling)) {
            return true;
        } else {
            return false;
        }
    }
}

/**
 * Checks whether the row is the last row
 */
function isTheLastRow(row) {
    if (row.nextSibling == null) {
        return true;
    } else {
        return false;
    }
}

/**
 * Checks whether the row is the last second row
 */
function isTheLastSecondRow(row) {
    if (row.nextSibling == null) {
         return false;
    } else {
        if (isTheLastRow(row.nextSibling)){
            return true;
        } else {
            return false;
        }
    }
}

function sortingData(lastClick, order) {
    this.lastClick = lastClick;
    this.order = order;
}

function imageData(ascending, descending, reverse) {
    this.ascending = ascending;
    this.descending = descending;
    this.reverse = reverse;
}

function getReadableCellValue(node, isChecked) {
    for (var j = 0; j < node.childNodes.length; j++) {
        var cellChild = node.childNodes[j];
        if (isReadableCell(cellChild.tagName)) {
            return getRowCellValue(cellChild, isChecked);
        }
    }
}

/**
 * @param imageData object, new imageData(ascendingImagePath, descendingImagePath, reverse)
 * @param sortingData object, new sortingData(lastClick, order)
 * @param dataType object, 'text' or 'number')
 * @param event
 */
function clientSideSorting(sorting, dataType, imageInfo, e) {
    /* get column No */
    var colNo = 0;
    var head = getEventElement(e);
    while (head[0].tagName != "THEAD")
    {
        head[0] = head[0].parentNode;
    }
    var headChild = head[0].getElementsByTagName("TR")[0].getElementsByTagName("TH");
    for ( i = 0; i < headChild.length; i++) {
        colNo = colNo + 1;
    }
    /* get necessary table elements for sorting */
    var tableElement = getEventElement(e);
    /* get clickColNo */
    var colValue;
    var clickColNo;
    var clickColValue;
    var clickCol;
    while(tableElement[0].tagName != "TH") {
        tableElement[0] = tableElement[0].parentNode;
    }
    clickCol = tableElement[0];
    clickColValue = getReadableCellValue(clickCol, true);
    for(i = 0; i < colNo; i++) {
        colValue = getReadableCellValue(clickCol.parentNode.getElementsByTagName("TH").item(i), true);
        if(clickColValue == colValue) {
            clickColNo = i + 1;
        }
    }
    /* decide the flag: reverse */
    var imagePath;
    sorting.order = (sorting.order + 1) % 3;
    if (sorting.lastClick == clickColNo) {
        if (sorting.order == 1) {
            imagePath = imageInfo.ascending;
        } else if (sorting.order == 2){
            imagePath = imageInfo.descending;
        } else {
            imagePath = '';
        }
    } else {
        sorting.order = 1;
        imageInfo.reverse = false;
        imagePath = imageInfo.ascending;
    }
    /* add the sorting image */
    if (!imageInfo.reverse) {
        /* change the last click node to the status
         * before sorting
         */
        if (sorting.lastClick != clickColNo && sorting.lastClick != 0) {
                headChild[sorting.lastClick - 1].removeChild(headChild[sorting.lastClick - 1].childNodes[1]);
        }
        var columnData  = getSpanValue(headChild[clickColNo - 1].firstChild);
        var columnId = headChild[clickColNo - 1].firstChild.getAttribute('Id');
        imageInfo.reverse = !imageInfo.reverse;
        var imgElem = document.createElement('IMG');
        imgElem.setAttribute("class", "imageSortOrder");
        imgElem.setAttribute("Id", columnId);
        imgElem.setAttribute("alt", "");
        imgElem.setAttribute("src", imagePath);
        headChild[clickColNo - 1].appendChild(imgElem);
    } else {
        // change the sorting order image
        var childElem = headChild[clickColNo - 1].childNodes;
        var imgElem = childElem[1];
        if (sorting.order != 0) {
            imgElem.setAttribute("src", imagePath);
        } else {
            headChild[clickColNo - 1].removeChild(imgElem);
            imageInfo.reverse = !imageInfo.reverse;
        }
    }
    sorting.lastClick = clickColNo;

    /* get the whole table */
    var tableBody;
    var tableRow;
    var tableRowData;
    var rowNo;
    while(tableElement[0].tagName != "TABLE") {
        tableElement[0] = tableElement[0].parentNode;
    }

    /* get the table data area */
    tableBody = tableElement[0].getElementsByTagName("TBODY").item(0);
    tableRow = tableBody.getElementsByTagName("tr");
    rowNo = tableRow.length;
    /* the insertion Sorting */
    insertionSortingTable(tableBody, colNo, clickColNo, sorting.order, dataType)
}

function getSortableNode(node) {
    var size = node.length;
    for (i = 0; i<size; i++) {
        var childNode = node.item(i);
        if (childNode.tagName == 'INPUT'
            && (childNode.type == 'radio' || childNode.type == 'checkbox' || childNode.type == 'hidden')) {
            continue;
        }
        else return childNode;
    }
    return '';
}

function insertionSortingTable(tableBody, colNo, clickColNo, order, dataType) {
    var currentComparedData, insertComparedData;
    var tableRowData = tableBody.getElementsByTagName("td");
    var rowNo = tableBody.getElementsByTagName("tr").length;

    for ( iRowInsert = 0 ; iRowInsert < rowNo - 1; iRowInsert++ ) {
        for ( iRowWalk = 0; iRowWalk <= iRowInsert ; iRowWalk++ ) {
            currentComparedData = getRowCellValue(
                getSortableNode(tableRowData.item(clickColNo + colNo * iRowWalk - 1).childNodes), true);
            insertComparedData = getRowCellValue(
                getSortableNode(tableRowData.item(clickColNo + colNo * (iRowInsert + 1) - 1).childNodes), true);

            if (dataType == 'number' &&  !isNaN(currentComparedData) &&  !isNaN(insertComparedData)) {
                currentComparedData = eval(currentComparedData);
                insertComparedData = eval(insertComparedData);
            } else {
                currentComparedData = currentComparedData.toLowerCase();
                insertComparedData = insertComparedData.toLowerCase();

            }
             if ((insertComparedData < currentComparedData && order != 2)
                     || (insertComparedData > currentComparedData && order == 2)) {
                 eRowInsert = tableBody.getElementsByTagName("tr").item(iRowInsert + 1);
                 eRowWalk = tableBody.getElementsByTagName("tr").item(iRowWalk);
                 tableBody.insertBefore(eRowInsert, eRowWalk);
                 iRowWalk = iRowInsert;
            }
        }
    }
}

function showToolTips(elementName, text) {
    var obj=document.getElementById(elementName);
    obj.title=text;
}
/**
 * used to get the special td name for deleting confirm
 * @param node Node
 * @param attributeId the checkbox's id, such as 'uuid'
 * @param index  which column that you want to get in the table
 */
function getLineName(node, attributeId, index) {
    var allRow = getCheckedRow(node, attributeId);
    if (allRow == null) return;
    var values = getCurrentRowValue(allRow[0], true, true);
    if (values == null) return;
    var name = values[index];
    if (name == null) return;
    return name;
}

var refRow;
var expandedRow = new Array();

function setRow(row, rowAttrs) {
    row.className = rowAttrs['class'];
    if (isIE5()) {
        row.onclick       = Function(rowAttrs['onclick']);
        row.oncontextmenu = Function(rowAttrs['oncontextmenu']);
        row.onmouseout    = Function(rowAttrs['onmouseout']);
        row.onmouseover   = Function(rowAttrs['onmouseover']);
    } else {
        row.setAttribute('onclick',       rowAttrs['onclick']);
        row.setAttribute('oncontextmenu', rowAttrs['oncontextmenu']);
        row.setAttribute('onmouseout',    rowAttrs['onmouseout']);
        row.setAttribute('onmouseOver',   rowAttrs['onmouseover']);
    }
}

function setCell(cell, className, colSpan, align, vAlign, value) {
    // set cell attribute(s)
    /*
    for (var i = 0; i < attributes.length; i++) {
        var attribute = attributes[i];
        var attrId = attribute.nodeName;
        var attrValue = attribute.nodeValue;
        if (attrId && attrValue) {
            cell.setAttribute(attrId, attrValue);
        }
    }
    */
    cell.className = className;
    if (colSpan > 1) {
        cell.colSpan = colSpan;
    }
    cell.align = align;
    cell.vAlign = vAlign;

    // set cell content
    if (!value || (value == '')) {
        value = '&nbsp;';
    }
    cell.innerHTML = value;
}

function insertRow(cellValues, rowAttrs) {
    var cacheImg = new Image();
    cacheImg.src = webPath  + 'images/icon_collapsed_small.gif';
    var viewTable = getTable(refRow);
    if (isNull(viewTable)) {
        return;
    }
    var rowId = getRowIndex(refRow);
    var row = viewTable.insertRow(rowId + 1);
    try {
        setRow(row, rowAttrs);

        var refCells = refRow.cells;
        for (var i = 0; i < refCells.length; i++) {
            var refCell = refCells[i];

            var cell = row.insertCell(i);
            setCell(cell,
                (i != 1) ? refCell.className : 'row_default_hierarchy_checkbox',
                refCell.colSpan,
                (i != 1) ? refCell.align : 'left',
                refCell.vAlign,
                cellValues[i]);
        }

        var refRowUuid = getNodeValueByIdGroup(refRow, "uuid", "INPUT");
        if (!expandedRow[refRowUuid]) {
            expandedRow[refRowUuid] = 0;
        }
        expandedRow[refRowUuid]++;

    } catch (e) {
        viewTable.deleteRow(rowId + 1);
    }
}

function insertRowString(str, rowAttrs) {
    var cacheImg = new Image();
    cacheImg.src = webPath  + 'images/icon_collapsed_small.gif';

    var viewTable = getTable(refRow);
    var rowId = getRowIndex(refRow);
    var row = viewTable.insertRow(rowId + 1);
    try {
        var rowAttr = new Array();
        rowAttr['class']         = rowAttrs['class'];
        rowAttr['onclick']       = 'return false';
        rowAttr['oncontextmenu'] = 'return false';
        rowAttr['onmouseover']   = rowAttrs['onmouseover'];
        rowAttr['onmouseout']    = rowAttrs['onmouseout'];
        setRow(row, rowAttr);

        var cell = row.insertCell(i);
        var refCells = refRow.cells;
        var totalColSpan = 0;
        for (var i = 0; i < refCells.length; i++) {
            totalColSpan += refCells[i].colSpan;
        }
        setCell(cell, 'row_default', totalColSpan, 'middle', 'center', str);

        var refRowUuid = getNodeValueByIdGroup(refRow, 'uuid', 'INPUT');
        if (!expandedRow[refRowUuid]) {
            expandedRow[refRowUuid] = 0;
        }
        expandedRow[refRowUuid]++;
    } catch(e) {
        viewTable.deleteRow(rowId + 1);
    }
}

function deleteRow() {
    var viewTable = getTable(refRow);
    var rowId = getRowIndex(refRow);
    var refRowUuid = getNodeValueByIdGroup(refRow, "uuid", "INPUT");
    for (var i = 0; i < expandedRow[refRowUuid]; i++) {
        viewTable.deleteRow(rowId + 1);
    }
    expandedRow[refRowUuid] = 0;
}

function getRowIndex(srcElem) {
    var rowIndex;
    if (isNull(getTable(srcElem))) {
        return;
    }
    var rows = getTable(srcElem).rows;
    for (var i = 0; i < rows.length; i++) {
        if (srcElem == rows[i]) {
            rowIndex = i;
            break;
        }
    }
    return rowIndex;
}

function expandView(event) {
    refRow = null;
    var srcElem = getEventElement(event);
    if (!isTableRow(srcElem[0])) return;
    refRow = getRow(srcElem[0]);

    var uuid = getNodeValueByIdGroup(refRow, "uuid", "INPUT");
    if (expandedRow[uuid] && expandedRow[uuid] > 0) {
        srcElem[0].src = webPath  + 'images/icon_collapsed_small.gif';
        srcElem[0].alt = collapsed;
        srcElem[0].title = collapsed;
        // bug fix 2695, add backgroundImage as same as image src
        srcElem[0].style.backgroundImage = 'url(' + webPath  + 'images/icon_collapsed_small.gif)';
        deleteRow();
    } else {
        srcElem[0].src = webPath  + 'images/icon_expanded_small.gif';
        srcElem[0].alt = expanded;
        srcElem[0].title = expanded;
        srcElem[0].style.backgroundImage = 'url(' + webPath  + 'images/icon_expanded_small.gif)';
        var url = contextPath + '/expandRelatedDocumentView.do';
        document.expandFrm.action = url;
        document.expandFrm.docId.value = uuid;
        submitForm(document.expandFrm);
    }
}

function setBodyCursor(style, frameName) {
    if (frameName != null) {
        if (typeof(frameName) != '' && typeof(frameName) != 'undefined') {
            if (top.frames[frameName].document.body) {
                top.frames[frameName].document.body.style.cursor = style;
            }
        }
    } else {
        document.body.style.cursor = style;
    }
}

function setBodyLocationCursor(style, frameName, location) {
    top.frames[frameName].location = location;
    // "if" is needed because the setting of location may be aborted by, e.g.
    // an onbeforeunload event
    if (top.frames[frameName].location == location) {
        setBodyCursor('wait', frameName);
    }
}

function submitForm(form, frameName) {
    if (!form.onsubmit || (form.onsubmit && form.onsubmit())) {
        setBodyCursor('wait', frameName);
        try {
            // known issue for Mozilla: if user has cancelled form submission,
            // e.g. by an unbeforeunload event, form.submit() will be skipped
            // and this cannot be detected and thus the cursor is not reset.
            form.submit();
        } catch (e) {
            // in IE, cancelling form submission will result in an error,
            // which is captured here
            setBodyCursor('auto', frameName);
        }
    }
    return;
}

function Tip(id, text, className) {
    this.id = id;
    this.text = text;
    this.className = className;
    this.obj = document.getElementById(this.id);
    this.createTip = createTip;
    this.showTip = showTip;
    this.hideTip = hideTip;
    this.moveTipTo = moveTipTo;
}

/**
 * create a tip object
 */
function createTip() {
    this.obj = document.getElementById(this.id);
    if (this.obj != null) {
        this.obj.innerHTML = '';
        document.getElementsByTagName('body').item(0).removeChild(this.obj);
    }
    this.obj = document.createElement('DIV');
    this.obj.id = this.id;
    this.obj.className = this.className;
    document.getElementsByTagName('body').item(0).appendChild(this.obj);
    var css = '<span>' + this.text + '</span>';
    this.obj.innerHTML = css;
}
/**
 * show the tip window
 */
function showTip() {
    if (this.obj != null) {
        this.obj.style.visibility = 'visible';
    }
}

/**
 * hidden the tip window
 */
function hideTip() {
    if (this.obj != null) {
        this.obj.style.visibility = 'hidden';
    }
}

/**
 * mouseout event occurs hide the tip window
 */
function outHideTip(obj) {
    if (obj != null) {
        obj.style.visibility = 'hidden';
    }
}

/**
 * move the tip window to a specified location
 * @param x the left limit of the tip window
 * @param y the upper limit of the tip window
 */
function moveTipTo(x, y) {
    if (this.obj != null) {
        this.obj.style.left = x + "px";
        this.obj.style.top = y + "px";
    }
}

/**
 * handle the mouse over event in this function
 * @ event the mouse move event object
 * @ id  of object which you want show
 * tip on it
 */
function tipHandler(event) {
    var srcElem = event.srcElement;
    if (srcElem && srcElem.tagName != 'SELECT') {
        oTip.hideTip();
    }
}

function mousemove(event, word) {
    if (word == null) {
        oTip.hideTip();
        return;
    }
    oTip = new Tip('tipId', word, 'tip');
    oTip.createTip();
    oTip.moveTipTo(event.clientX, event.clientY);
    oTip.showTip();
}

function onMultiRowAction(nextAction, actionType, rowParent, extraValue) {
    var data = getNodeValueByIdGroup(rowParent, 'uuid', 'INPUT', true);
    if (!haveData(data)) {
       alert(messageEmptySelect);
       return;
    }
    if (typeof(oMenu) != "undefined") {
        oMenu.hideSimpleMenu();
    }
    var functionStr = nextAction + '(';
    if (actionType != null && actionType != '') {
        functionStr += '"' + actionType + '", ';
    }
    if (extraValue != null) {
        functionStr += 'data, extraValue)';
    } else {
        functionStr += 'data)';
    }
    eval(functionStr);
}

function passSingleRowValidation(e, checkRowData) {
    if (typeof(oMenu) != "undefined") {
        oMenu.hideSimpleMenu();
    }
    var srcElem = getEventElement(e);
    if(!isTableRow(srcElem[0]))
        return false;
    if(isFormElementNode(srcElem[0]))
        return false;
    var rowData = new Array;
    if (checkRowData != false) {
        var rowElem = getRow(srcElem[0]);
        rowData.push(getNodeValueByIdGroup(rowElem, 'uuid', 'INPUT', false));
        rowData.push(getCurrentRowValue(rowElem, false, true, true));
        rowData.push(rowElem);
        rowData.push(srcElem);
        if (!haveData(rowData[0])) {
            return false;
        }
    }
    return rowData;
}

function checkRow(event, srcElem) {
    var eventElem;
    if (!srcElem) {
        eventElem = getEventElement(event)[0];
    } else {
        eventElem = srcElem;
    }
    var node = getRow(eventElem).getElementsByTagName('INPUT');
    node[0].checked = !node[0].checked;
}

/**
 * get table row
 * @param row html table row
 * @return array values
 */
function getImageValue(rowElem, fieldId) {
    var value = '';
	var images = rowElem.getElementsByTagName('IMG');
    for (var i = 0; i < images.length; i++) {
        if (images[i].id) {
            var imageId = images[i].id;
            if (imageId.indexOf(fieldId + '_') == 0) {
                value = imageId.substring(imageId.lastIndexOf('_') + 1);
                break;
            }
        }
    }
    if (value == '') {
    	var spans = rowElem.getElementsByTagName('SPAN');
        for (var i = 0; i < spans.length; i++) {
            if (spans[i].id) {
                var spanId = spans[i].id;
                if (spanId.indexOf(fieldId + '_') == 0) {
                    value = spanId.substring(spanId.lastIndexOf('_') + 1);
                    break;
                }
            }
        }
    }
    return value;
}

/*
 * The method used to change the image state.
 * Toolbar images name should be: <labelId>_<state>.gif
 * where <state> can be "out", "over", "down".
 * Each item should be in 3 states: mouse out(default), mouse over, mouse click.
 */
function onMouseImage(event, state) {
    var imgElem = getEventElement(event)[0];
    if (imgElem != null) {
        var prefix = imgElem.src.substring(0, imgElem.src.lastIndexOf('_'));
        imgElem.src = prefix + '_' + state + '.gif';
    }
}

function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

<!-- This one controls the swapimage and mouseout/over functions -->
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
